
package com.ltg.widget;

import android.content.Context;
import android.text.method.ScrollingMovementMethod;
import android.util.AttributeSet;
import android.widget.TextView;

import java.io.PrintWriter;
import java.io.StringWriter;

public class TestView extends TextView {

    public TestView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        setMovementMethod(ScrollingMovementMethod.getInstance());
    }

    public TestView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setMovementMethod(ScrollingMovementMethod.getInstance());
    }

    public TestView(Context context) {
        super(context);
        setMovementMethod(ScrollingMovementMethod.getInstance());
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        updateStack();
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        updateStack();
    }

    public void updateStack() {
        StringWriter str = new StringWriter();
        new RuntimeException().printStackTrace(new PrintWriter(str));
        append(str.toString());
    }

}
